using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Child2 : MonoBehaviour
{

    public Transform son;

    // Start is called before the first frame update
    void Start()
    {
        // 丢弃所有的子对象
        //this.transform.DetachChildren();

        // 按名字查找子对象
        //Transform transform = this.transform.Find("Sphere");
        //print(transform);

        // 统计孩子数量
        print(this.transform.childCount);
        for (int i = 0; i < this.transform.childCount; i++)
        {
            // 根据子对象的编号获取子对象, 超出范围会报错的.
            var child = this.transform.GetChild(i);
            print("子对象名字: " + child.name);
        }

        if (son.IsChildOf(this.gameObject.transform))
        {
            print("son是当前对象的子对象.");
        }

        print("son作为子对象的编号: " + son.GetSiblingIndex());

        // 设置子对象的编号为制定编号
        son.SetSiblingIndex(2);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
